import fs from 'fs'
import path from 'path'
import { pathToFileURL } from 'url'

const handleHtmlRouter = async (req, res) => {
	// 设置返回格式 html
	res.setHeader('Content-type', 'text/html')
	const __dirname = pathToFileURL(process.cwd()).pathname

	if (req.path === '/') {
		return fs.readFileSync(path.resolve(__dirname, './front-end/index.html'))
	}

	if (req.path.endsWith('html')) {
		return fs.readFileSync(path.resolve(__dirname, `./front-end/${req.path}`))
	}
}

export { handleHtmlRouter }
